// HanWangControlDemo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>
#include "../Lib/HWControlLinkDef.h"
#include <iostream>
#include <wchar.h>
#include <assert.h>


#pragma comment(lib, "../lib/HwControllink.lib")

using namespace std;

HWCtrlDeviceTime ReadTime() 
{
	HWCtrlDeviceTime time;
	bool result = HWCtrlLinkCommand(HWCTRL_COMMAND_GET_TIME, &time, NULL, 500);
	cout<<result<<endl;
	return time;
}


void _stdcall CallBack(tagHWCtrlEvent evt)
{

	switch(evt.type)
	{
	case HWCTRL_EVENT_ESTABLISH:
		{
		cout<<"connected"<<endl;
		Sleep(3000);
		 //ReadTime();
		}
		break;
	default:
		wprintf(L"%s\n", evt.szMsg);
	}
}


int _tmain(int argc, _TCHAR* argv[])
{
	setlocale(LC_ALL, "chs");
	HWCtrlLinkParam parm;
	parm.ip = 4211189952; //192.168.1.251
	parm.port = 5225;
	parm.callback = CallBack;

	HWCtrlLinkConnect(parm);

	Sleep(3000);

	HWCtrlDeviceTime time = ReadTime();
	time.month += 1;

	bool result = HWCtrlLinkCommand(HWCTRL_COMMAND_UPDATE_TIME, &time, NULL, 500);

	cout<<"update time: "<<result<<endl;
	
	HWCtrlDeviceTime newTime = ReadTime();
	assert(newTime.month == time.month + 1);

	int i;
	cin>>i;

	return 0;
}

